package com.ruoyi.web.controller.sale;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HhOrderDetail;
import com.ruoyi.system.service.IHhOrderDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售订单明细Controller
 * 
 * @author ruoyi
 * @date 2021-06-15
 */
@RestController
@RequestMapping("/sale/detail")
public class HhOrderDetailController extends BaseController
{
    @Autowired
    private IHhOrderDetailService hhOrderDetailService;

    /**
     * 查询销售订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('sale:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(HhOrderDetail hhOrderDetail)
    {
        startPage();
        List<HhOrderDetail> list = hhOrderDetailService.selectHhOrderDetailList(hhOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出销售订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('sale:detail:export')")
    @Log(title = "销售订单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HhOrderDetail hhOrderDetail)
    {
        List<HhOrderDetail> list = hhOrderDetailService.selectHhOrderDetailList(hhOrderDetail);
        ExcelUtil<HhOrderDetail> util = new ExcelUtil<HhOrderDetail>(HhOrderDetail.class);
        return util.exportExcel(list, "销售订单明细数据");
    }

    /**
     * 获取销售订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:detail:query')")
    @GetMapping(value = "/{odId}")
    public AjaxResult getInfo(@PathVariable("odId") Long odId)
    {
        return AjaxResult.success(hhOrderDetailService.selectHhOrderDetailById(odId));
    }

    /**
     * 新增销售订单明细
     */
    @PreAuthorize("@ss.hasPermi('sale:detail:add')")
    @Log(title = "销售订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HhOrderDetail hhOrderDetail)
    {
        return toAjax(hhOrderDetailService.insertHhOrderDetail(hhOrderDetail));
    }

    /**
     * 修改销售订单明细
     */
    @PreAuthorize("@ss.hasPermi('sale:detail:edit')")
    @Log(title = "销售订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HhOrderDetail hhOrderDetail)
    {
        return toAjax(hhOrderDetailService.updateHhOrderDetail(hhOrderDetail));
    }

    /**
     * 删除销售订单明细
     */
    @PreAuthorize("@ss.hasPermi('sale:detail:remove')")
    @Log(title = "销售订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{odIds}")
    public AjaxResult remove(@PathVariable Long[] odIds)
    {
        return toAjax(hhOrderDetailService.deleteHhOrderDetailByIds(odIds));
    }
}
